﻿@model IEnumerable<WeProjects.Models.NewsModel>

@{
    ViewBag.Title = "Index";
}
<style type="text/css">
    div.col-xs-12:first-child {
        border-top:0 !important;
    }
    .pub {
    }
    .row .row h4 {
        padding-top:0 !important;
        padding-bottom:10px !important;
    }
    .row .row p {
        margin-bottom:6px !important;
    }
</style>
<h2>新闻列表</h2>
@using (Html.BeginForm())
{
    <div class="buttonIn">
        <span>标签：</span>
        @{IList<WeProjectsModel.Tag> tags = (IList<WeProjectsModel.Tag>)(ViewBag.Tags);}
        @for (int x = 0; x < tags.Count(); x++)
        {
            <span style="padding-right:10px;">
                @Html.CheckBox("Tags[" + x + "].Selected", false) @tags[x].Name
                @Html.Hidden("Tags[" + x + "].Name", tags[x].Name)
                @Html.Hidden("Tags[" + x + "].Code", tags[x].Code)
            </span>
        }
        @Html.TextBox("keyword")
        <input type="submit" value="查询" class="btn btn-info" />
    </div>
}
<div class="row">
@foreach (var item in Model) {
    <div class="col-xs-12" style="border-top: 1px solid #ecebeb;padding-top:20px;padding-bottom:20px;">
        <div class="row">
            <div class="col-xs-2">
                <div style="width: 100%; max-height: 110px; overflow:hidden">
                    <img src=@item.ImageData style="width:150%;height:150%;margin-left:-25%;" />
                </div>
            </div>
            <div class="col-xs-10" style="position:relative;">
                <h4 style="padding-bottom:15px;">@Html.ActionLink(item.Title, "Details", new { id = item.ID }) <small> 所属项目：@Html.DisplayFor(modelItem => item.ProjectTitle).@Html.DisplayFor(modelItem => item.ParentProjectTitle)</small></h4>
                <p style="margin-bottom:15px;">
                    @if (item.NewsContent != null && item.NewsContent.Length > 81)
                    {
                        @Html.Raw(item.NewsContent.StripHtmlTags().Substring(0, 80))
                    }
                    else
                    {
                        @Html.Raw(item.NewsContent.StripHtmlTags())
                    }
                </p>
                <p style="color:#999;">
                    <span style="display:inline-block;width:48%;">
                        标签：
                        @if (item.Tags != null)
                        {
                            foreach (var t in item.Tags)
                            {
                                if (t.Selected)
                                {
                                    <span> @t.Name；&emsp;</span>
                                }
                            }
                        }
                    </span>
                    <span style="display:inline-block;width:20%;">作者： @Html.DisplayFor(modelItem => item.MemberDispalyName)</span>
                    <span style="display:inline-block;width:20%;">创建时间： @item.PublishDate.Value.ToShortDateString()</span>
                </p>
                <p class="pub text-right">
                    @if (Roles.IsUserInRole("sysadmin"))
                    {
                        @Html.Raw((item.isPublished == 0) ? "未发布 " + Html.ActionLink("点此发布", "NewsPublish", new { newsId = item.ID, pub = 1 }, new { @class = "btn btn-success btn-small" }) : "已发布 " + Html.ActionLink("取消发布", "NewsPublish", new { newsId = item.ID, pub = 0 }, new { @class = "btn btn-danger btn-small" }))
                    }
                </p>
            </div>
        </div>
    </div>
}
</div>

@*<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Title)
        </th>
        <th>
            Tags
        </th>
        <th>
            @Html.DisplayNameFor(model => model.PublishDate)
        </th>
        <th>
            发布者
        </th>
        <th>
            内容
        </th>
        <th>图片</th>
        <th>
            @Html.DisplayNameFor(model => model.isPublic)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.isPublished)
        </th>
        <th>操作</th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.ActionLink(item.Title, "Details", new { id = item.ID })-{@Html.DisplayFor(modelItem => item.ProjectTitle).@Html.DisplayFor(modelItem => item.ParentProjectTitle)}
        </td>
        <td>
            @if(item.Tags!=null)
            { 
                foreach( var t in item.Tags)
                {
                    if(t.Selected)
                    { 
                        @Html.Label(t.Name+";")
                    }
                }
            }
        </td>
        <td>
            @Html.Label(item.PublishDate.Value.ToShortDateString())
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.MemberDispalyName)
        </td>
        <td>
            @if(item.NewsContent.Length>51)
            { 
            @Html.Raw(item.NewsContent.StripHtmlTags().Substring(0,50))
            }
            else
            { 
                @Html.Raw(item.NewsContent.StripHtmlTags())
            }
        </td>
        <td><img src=@item.ImageData /></td>
        <td>
            @Html.DisplayFor(modelItem => item.isPublic)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.isPublished)
        </td>
        <td>
            @if(Roles.IsUserInRole("sysadmin"))
            { 
                @Html.Raw((item.isPublished == 0) ? "未发布 " + Html.ActionLink("点此发布", "NewsPublish", new { newsId = item.ID, pub = 1 }, new { @class = "btn btn-success btn-small" }) : "已发布 " + Html.ActionLink("取消发布", "NewsPublish", new { newsId = item.ID, pub = 0 }, new { @class = "btn btn-danger btn-small" }))
            }
            @Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
            @Html.ActionLink("Details", "Details", new { id=item.ID }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.ID })
        </td>
    </tr>
}

</table>*@
